<template>
  <div>
    <van-cell-group>
      <van-field v-model="displayCourse.type" label="课程类型" disabled/>
      <van-field v-model="course.kcname" label="课程名称" disabled/>
      <van-field v-model="displayCourse.student" label="学生姓名" disabled/>
      <van-field v-model="displayCourse.time" label="上课时间" disabled/>
      <van-field v-model="displayCourse.address" label="上课地点" disabled/>
      <van-field v-model="displayCourse.repeat" label="重复方式" disabled/>
    </van-cell-group>
  </div>
</template>

<script>
import api from '@/api'
import {datetimeFormat} from '@/utils'
export default {
  name: 'course-detail',
  data () {
    return {
      course: {
        id: '',
        kech: 1,
        kcname: '',
        type: 1,
        sktime: '',
        xktime: '',
        dqplace: '',
        skplace: ''
      },
      displayCourse: {
        type: '',
        student: '',
        time: '',
        repeat: ''
      }
    }
  },
  methods: {
    getInfo () {
      api.platformCourseDetail({
        params: {kcid: this.$route.query.id},
        callback: res => {
          if (res.data.error_code === 0) {
            Object.keys(this.course).forEach(key => {
              this.course[key] = res.data.data[key]
            })
            if (res.data.data.kech === 1) {
              this.displayCourse.type = 'VIP一对一课程'
            } else {
              this.displayCourse.type = '集体课程'
            }
            this.displayCourse.address = res.data.data.dqplace + res.data.data.skplace
            let names = []
            res.data.data.student.forEach(item => {
              names.push(item.name)
            })
            this.displayCourse.student = names.join(',')
            this.displayCourse.time = datetimeFormat(new Date(Number(res.data.data.sktime) * 1000))
            if (res.data.data.type === 1) {
              this.displayCourse.repeat = '每周'
            } else if (res.data.data.type === 2) {
              this.displayCourse.repeat = '隔周'
            } else if (res.data.data.type === 3) {
              this.displayCourse.repeat = '不重复'
            }
          }
        }
      })
    }
  },
  created () {
    this.getInfo()
  }
}
</script>

<style scoped>

</style>
